function Submit(formname,target)
{

	 
	var formid =document.getElementById(formname);
	
	var isform = Validator.Validate(formid,3);
	

	if(!isform)
	{
		return false;
	}else
	{
	   
	   formid.action = "";
	   formid.action = target;
	   formid.submit();
	   return true;
		
	
	}

}

function BtnDel(lang,url)
{
	if(confirm(lang))
	{
		jumpto(url);	
	}
}

function jumpto(url)
{
	location.href = url;
}
function BtnSo()
{
	var s = document.getElementById("s");
	var e = document.getElementById("e");
	var t = document.getElementById("t");
	if(s.value=="")
	{
		alert("请输入关键词");
		s.focus();
		
	}else
	{
		location.href=baseurl+"users/lists/?s="+s.value+"&e="+e.value+"&t="+t.value;
		
	}
}
function GetCompany(obj)
{
	if(obj.value>0)
	{
		Ajax.call(baseurl+"api/getcompany/", "areaid="+obj.value+"&rand="+Math.random(), ResponseCompany, "POST", "JSON", false);
	}
}
function ResponseCompany(result)
{
	var company = document.getElementById("company");
	company.innerHTML = "";
	for(var i=0;i<result.length;i++){
		company.add(new Option(result[i]["company"],result[i]["companyid"]));
	}

}

function docart(foodid,num,run,obj)
{
	
		Ajax.call(baseurl+"orders/docart/", "foodid="+foodid+"&num="+num+"&run="+run+"&obj="+obj+"&rand="+Math.random(), ResponseDocart, "POST","JSON");
	
}


function   titleshow(txt) 
{ 
	document.all.divshow.style.display= "block "; 
	
	document.all.divshow.style.left=event.x; 
	document.all.divshow.style.top=event.y; 
	document.all.divshow.innerText=txt; 

} 
function ResponseDocart(result)
{
	
	if(result.error)
	{
		alert(result.content);
	}else
	{
		if(result.obj=="info")
		{
			CartReload();
		}else
		{
			if(top.location!=location) location.reload();
		}
		
	}
		
}

function CartReload()
{
	document.getElementById("cart_step").src=baseurl+"orders/step/"+Math.random();	
}
function GetEat(eatid)
{
	if(eatid>0)
	{
		document.getElementById("foodlist").innerHTML="";
		document.getElementById("food_loading").style.display="";
		Ajax.call(baseurl+"api/geteatfood/", "eatid="+eatid+"&rand="+Math.random(), ResponsGetEat, "POST","JSON");	
	}
}
function ResponsGetEat(result)
{
	
	if(result.error)
	{
		document.getElementById("food_loading").style.display="none";
		document.getElementById("refood").innerHTML = result.result;
	}else
	{
		alert("暂无该商家的数据")	
	}
}

function check(v)
{
	var inputs = document.getElementsByTagName('input');
	var inputsLen = inputs.length;
	for (var i = 0; i < inputsLen ; i++ )
	{
		if (inputs[i].type.toLowerCase() == 'checkbox')
		{
			//inputs[i].checked == true ? inputs[i].checked = false:inputs[i].checked = true;
			
			inputs[i].checked = v.checked;
		}
	}
}
 function check_team()
{
	var inputs = document.getElementsByTagName('input');
	var inputsLen = inputs.length;
	for (var i = 0; i < inputsLen ; i++ )
	{
		if (inputs[i].type.toLowerCase() == 'checkbox')
		{
			//inputs[i].checked == true ? inputs[i].checked = false:inputs[i].checked = true;
			
			inputs[i].checked = true;
		}
	}
}

function dyniframesize(down) 
{ 
	var pTar = null; 
	if (document.getElementById){ 
	pTar = document.getElementById(down); 
	} 
	else{ 
	eval('pTar = ' + down + ';'); 
	} 
	if (pTar && !window.opera){ 
	//begin resizing iframe 
	pTar.style.display="block" 
	if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){ 
	//ns6 syntax 
	pTar.height = pTar.contentDocument.body.offsetHeight +30; 
	//pTar.width = pTar.contentDocument.body.scrollWidth+20; 
	} 
	else if (pTar.Document && pTar.Document.body.scrollHeight){ 
	//ie5+ syntax 
	pTar.height = pTar.Document.body.scrollHeight; 
	//pTar.width = pTar.Document.body.scrollWidth; 
	} 
	} 
}
function ShowObj(obj)
{
	if(document.getElementById(obj).style.display=="")
	{
		document.getElementById(obj).style.display="none";
	}else
	{
		document.getElementById(obj).style.display="";
	}
}

function RunLogin(u,p,isremember)
{
	var username = document.getElementById(u).value;
	
	var password = document.getElementById(p).value;
	
	var isremember = document.getElementById(isremember).checked;
	
	if(username!="" && password!="")
	{
		Ajax.call(baseurl+"member/logincheck/", "username="+username+"&password="+password+"&isremember="+isremember+"&rand="+Math.random(), ResponsRunLogin, "POST","JSON");		
	}else
	{
		alert("请输入用户名和密码");	
	}
}
function ResponsRunLogin(result)
{
	
   if(result.error)
   {
		alert("登陆失败,用户名或密码错误");
		
   }else
   {
		jumpto(baseurl+"orders");   
   }
}

function LoginWindow()

{

	 var htmlcontent = "<ul class=\"loginq\"><li>姓名：<input type=\"text\" name=\"ui_username\" value=\"\" class=\"inputk2\" id=\"ui_username\" /></li><li>密  码:<input type=\"password\" name=\"ui_password\" value=\"\" class=\"inputk2\" id=\"ui_password\" /></li><li>自动登录<input name=\"ui_isremember\" type=\"checkbox\" id=\"ui_isremember\" style=\"margin-left:32px;\" value=\"1\" checked=\"checked\" /></li><li><input type=\"button\" name=\"ui_tijiao\" value=\"登陆\"  class=\"plbtn\" onclick=\"RunLogin('ui_username','ui_password','ui_isremember');return false;\" id=\"ui_tijiao\"/></li></ul>";
      
	  ShowMessage(300,170,htmlcontent,'请先登陆','#FCF4EF');
	  
	  document.getElementById("ui_username").focus();

}
function message()
{
	var isuser = document.getElementById("isuser").value;
	

	
	if(isuser=="0")
	{
		LoginWindow();
	}else
	{
		var message = document.getElementById("message");
		if(message.value=="")
		{
			alert("请填写留言内容");
			message.focus();	
		}else
		{
			Ajax.call(baseurl+"message/save/", "message="+message.value+"&rand="+Math.random(), ResponsMessage, "POST","JSON");	
		}
	}
	
}
function ResponsMessage(result)
{
	if(!result.error)
	{
		document.getElementById("message").value = "";
		document.getElementById("messagelist").innerHTML = result.content;
	}
}
function Replay(m)
{
	document.getElementById("message").focus();
	document.getElementById("message").value = "回复@"+m+":";
}
function Myorder(orderid,m)
{
	if(m=="1")
	{
		alert("订单已经处理了,不能退单.");	
	}else
	{
		if(confirm("您确认退单吗?"))
		{
			Ajax.call(baseurl+"orders/myorders/", "orderid="+orderid+"&rand="+Math.random(), ResponsMyorder, "POST","JSON");	
		}
		
	}
}
function ResponsMyorder(result)
{
	if(result.error)
	{
		alert(result.content);
	}else
	{
		location.reload();
	}
}
function CheckUser(showbox)
{
	
	var showbox = (typeof(showbox) === "string")?"close":"show";

	Ajax.call(baseurl+"member/checkuser/","showbox="+showbox+"&rand="+Math.random(), ResponsCheckUser, "POST","JSON");	
}
function ResponsCheckUser(result)
{
	
	if(result.success==1)
	{
		
		if(result.showbox!="close")
		{
			LoginWindow();
		}
	}else if(result.success==2)
	{
		location.reload();
	}	
}
function Logout()
{
	Ajax.call(baseurl+"member/logout/","rand="+Math.random(), ResponsLogout, "POST","JSON");		
}
function ResponsLogout(result)
{
	if(result.success)
	{
		location.reload();	
	}
		
}



function AddSort()
{
	var sortname = document.getElementById("sortname");
	if(sortname.value!="")
	{
		
		Ajax.call(admin_base_url+"sysadd/sortadd/","sortname="+sortname.value+"&rand="+Math.random(), ResponseAddSort, "POST","JSON");
	}else
	{
		alert("请输入类别名称");
		sortname.focus();
	}
}
function ResponseAddSort(result)
{
	
	
	if(result.error)
	{
		alert(result.message);
	}else
	{
		
		document.getElementById("SortList").style.display="";
		document.getElementById("SortAdd").style.display="none";
		var sorts = document.getElementById("sort");
		var re = result.message;
		sorts.innerHTML = "";
		for(var i=0;i<re.length;i++){
			sorts.add(new Option(re[i]["names"],re[i]["sortid"]));
		}
		alert("添加成功,请选择");
	}
	

}

